package cn.tedu.review;
/*本类用于复习多态*/
public class TestDemo {
    public static void main(String[] args) {
//        创建多态对象进行测试：继承+重写&父类引用指向子类对象&编译看左边，运行看右边
        Fruit f0 = new Fruit();
        f0.clean();
        Fruit f1 =new Apple();
        Fruit f2 = new Lemon();
        f1.clean();
        f2.clean();
        System.out.println(f0.name);
        System.out.println(f1.name);
        System.out.println(f2.name);
        getFruit(f0);
        Apple a = new Apple();
        getFruit(a);
        Lemon l = new Lemon();
        getFruit(l);
    }
    public static void getFruit(Fruit f2){
        f2.clean();
    }
}
//水果类
class Fruit{
    String name = "水果";
    public void  clean(){
        System.out.println("父类的clean（）");
    }
}
//子类
class Apple extends Fruit{
    String name = "苹果";
    @Override
    public void clean(){
        System.out.println("苹果类的clean（）");
    }
}
class Lemon extends Fruit{
    String name ="柠檬";
    @Override
    public void clean(){
        System.out.println("柠檬类的clean()");
    }

}